$(function() {
	$('#vue_vm_list div').hide();
});

var leaseSupplies = {
	leaseSuppliesId: '',
	suppliesName: '',
	brand: '',
	model: '',
	price: '',
	cashPledge: '',
	rent: '',
	stockNumber: '',
	iconUrl: '',
	intro: '',
	leaseNumber: '',
	status: '',
	createTime: '',
	updateTime: '',
	createId: getLoginedUser()? getLoginedUser().staffId: '',
	updateId: getLoginedUser()? getLoginedUser().staffId: '',
	remark: '',
};

var view = {
	data: leaseSupplies
};

var vue_vm = new Vue({
	el: '#vue_vm',
	data: view
});

findAll();

function save() {
	view.data.price = (view.data.price==''? 0: parseFloat(view.data.price));
	view.data.cashPledge = (view.data.cashPledge==''? 0: parseFloat(view.data.cashPledge));
	view.data.rent = (view.data.rent==''? 0: parseFloat(view.data.rent));
	view.data.stockNumber = (view.data.stockNumber==''? 0: parseInt(view.data.stockNumber));
	view.data.leaseNumber = (view.data.leaseNumber==''? 0: parseInt(view.data.leaseNumber));
	view.data.status = (view.data.status==''? 0: parseInt(view.data.status));

	save_basic(path+'/leaseSupplies/save', {leaseSupplies:view.data}, function() {
		alert('保存成功');
		findAll();
	});
}

function findAll() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();

	findAll_basic(path+'/leaseSupplies/findAll', function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				deleteBatchById: function(leaseSuppliesId) {
					var itemIdArray = [leaseSuppliesId];
					
					deleteBatch_basic_by_array(path+'/leaseSupplies/deleteBatch', itemIdArray, function(response) {
						$('#'+leaseSuppliesId).remove();
					});
				},
				getImageFullPath: function(iconUrl) {
					return imagePath + '/' + iconUrl;
				},
				update: function(todo) {
					todo.price = (todo.price==''? 0: parseFloat(todo.price));
					todo.cashPledge = (todo.cashPledge==''? 0: parseFloat(todo.cashPledge));
					todo.rent = (todo.rent==''? 0: parseFloat(todo.rent));
					todo.stockNumber = (todo.stockNumber==''? 0: parseInt(todo.stockNumber));
					todo.leaseNumber = (todo.leaseNumber==''? 0: parseInt(todo.leaseNumber));
					todo.status = (todo.status==''? 0: parseInt(todo.status));
				
					save_basic(path+'/leaseSupplies/save', {leaseSupplies:todo}, function() {
						alert('保存成功');
					});
				}
			}
		});
		
		$('#vue_vm_list div').show();
	});
}

function deleteBatch() {
	deleteBatch_basic(path+'/leaseSupplies/deleteBatch');
}
